In [ ]:
'''Question-1'''
In [1]:
import seaborn as sns
titanic = sns.load_dataset('titanic')
titanic.head()
Out[1]:
survived pclass sex age sibsp parch fare embarked class who adult_male deck embark_town alive alone
0 0 3 male 22.0 1 0 7.2500 S Third man True NaN Southampton no False
1 1 1 female 38.0 1 0 71.2833 C First woman False C Cherbourg yes False
2 1 3 female 26.0 0 0 7.9250 S Third woman False NaN Southampton yes True
3 1 1 female 35.0 1 0 53.1000 S First woman False C Southampton yes False
4 0 3 male 35.0 0 0 8.0500 S Third man True NaN Southampton no True
In [2]:
import plotly.express as px
# Plot a scatter plot for "age" and "fare" columns using Plotly express
fig = px.scatter(titanic, 
                 x="age",
                 y="fare", 
                 title="Titanic Dataset: Age vs. Fare")

# Update the layout to center the title above the plot
fig.update_layout(
    title={
        'text': "Titanic Dataset: Age vs. Fare",
        'y':0.95,
        'x':0.5,
        'xanchor': 'center',
        'yanchor': 'top'})

fig.show()
In [16]:
'''Question-2'''
Out[16]:
'Question-2'
In [3]:
import plotly.express as px
tips = px.data.tips()
tips.head()
Out[3]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
In [18]:
# Plot a box plot for the "total_bill" column using Plotly express
fig = px.box(tips,x='day',y="total_bill", title="Tips Dataset: Total Bill Box Plot")
fig.show()
In [19]:
'''Question-3'''
Out[19]:
'Question-3'
In [20]:
# Plot a histogram for "sex" and "total_bill" columns using Plotly express
fig = px.histogram(tips, x="sex", y="total_bill", 
                   color="day", pattern_shape="smoker",
                   title="Tips Dataset: Total Bill by Gender and Smoking Status")

fig.show()
In [21]:
'''Quetion-4'''
Out[21]:
'Quetion-4'
In [9]:
pip install plotly --upgrade
Requirement already satisfied: plotly in /opt/homebrew/anaconda3/lib/python3.11/site-packages (5.9.0)
Collecting plotly
  Obtaining dependency information for plotly from https://files.pythonhosted.org/packages/a8/07/72953cf70e3bd3a24cbc3e743e6f8539abe6e3e6d83c3c0c83426eaffd39/plotly-5.18.0-py3-none-any.whl.metadata
  Downloading plotly-5.18.0-py3-none-any.whl.metadata (7.0 kB)
Requirement already satisfied: tenacity>=6.2.0 in /opt/homebrew/anaconda3/lib/python3.11/site-packages (from plotly) (8.2.2)
Requirement already satisfied: packaging in /opt/homebrew/anaconda3/lib/python3.11/site-packages (from plotly) (23.1)
Downloading plotly-5.18.0-py3-none-any.whl (15.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 15.6/15.6 MB 7.8 MB/s eta 0:00:0000:0100:01
Installing collected packages: plotly
  Attempting uninstall: plotly
    Found existing installation: plotly 5.9.0
    Uninstalling plotly-5.9.0:
      Successfully uninstalled plotly-5.9.0
Successfully installed plotly-5.18.0
Note: you may need to restart the kernel to use updated packages.
In [4]:
import plotly.express as px

# Load the "iris" dataset from Plotly
iris = px.data.iris()

# Plot a scatter matrix plot using Plotly express
fig = px.scatter_matrix(
    iris,
    dimensions=["sepal_length", "sepal_width", "petal_length", "petal_width"],
    color="species",
    title="Iris Dataset: Scatter Matrix Plot"
)

# Show the plot
fig.show()
In [ ]:
'''Question-5'''
In [5]:
'''
In Plotly Express, the distplot function is used to create a distribution plot (histogram) for univariate data. 
It provides a visual representation of the distribution of a single continuous variable. 
The distplot combines a histogram with a kernel density estimate (KDE) to give a smooth representation of the underlying distribution.'''

import plotly.express as px
tips = px.data.tips()
fig = px.histogram(tips, x="total_bill", y="tip", color="sex",
                   marginal="box", # or violin, rug
                   hover_data=tips.columns)
fig.show()
In [ ]: